<?php 
		
		$user_name = $_POST['name'];
		$email = $_POST['email'];
		$password = sha1($user_name);
		$db = mysqli_connect("localhost","root","","ajax_form");

		$querys = "SELECT user_name, email FROM signup WHERE user_name='".$user_name."'";
		$results = mysqli_query($db,$querys);
		$row = mysqli_fetch_array($results);

		if(mysqli_num_rows($results) > 0) {
			if(strcmp($row['email'],$email)==0) {
				$query = "UPDATE signup 
						  SET password='".$password."' 
						  WHERE user_name='".$user_name."'";
				$result = mysqli_query($db,$query);

				$to = $_POST['email'];
				$header = "Jquery AJAX Supper Form + PHP & MYSQL";
				$subject = "New Password";

				$body = "Ngày: ". date('d/m/Y')."\n";
				$body .= "Username: ".$user_name . " - Email:" . $email . "\n";
				$body .= "Your password: ".$user_name;
				$headers = "From: $header \n";

				mail($to, $subject, $body, $headers);
				echo "true";
			} else {
				echo "false";
			}
		} else {
			echo "false";
		}
		
		

	

?>